package com.wink.admin.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

import java.sql.Timestamp;

/**
 * mybatis-plus自动填充处理器
 *
 * @author xw
 * @date 2021-01-07 16:55
 */
public class MybatisPlusAutoFillHandler implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {
        setFieldValByName("createdDate", new Timestamp(System.currentTimeMillis()), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        if (metaObject.hasSetter("lastModifyDate")) {
            this.setFieldValByName("lastModifyDate", new Timestamp(System.currentTimeMillis()), metaObject);
        }
        if (metaObject.hasSetter("updatedBy")) {
            this.setFieldValByName("updatedBy", "系统默认", metaObject);
        }
    }
}
